//           imprimir.C
//  Qua julho 13 07:56:42 2011
//  Copyright  2011  Alcione Ferreira
//  <user@host>

#include <imprimir.h>

/**
 * 
 */
PrintFormOperation::PrintFormOperation()
	{
	}

/**
 * 
 */
PrintFormOperation::~PrintFormOperation()
	{
	}

/**
 * 
 */
Glib::RefPtr<PrintFormOperation> PrintFormOperation::create()
	{
  	return Glib::RefPtr<PrintFormOperation>(new PrintFormOperation());
	}

/**
 * 
 */
void PrintFormOperation::set_cabecalho() 
	{
	this->m_cabecalho.clear(); 
	Glib::ustring Texto, AUX;
	int deslocar, i;

	Texto.clear();
	Texto = "          TABELIONATO OLIVEIRA";
	this->m_cabecalho = "<span size='12288'><b>"+Texto+"</b></span>\n";
	Texto.clear();
	Texto = "               Bel. Marcelino Cesar Medeiros de Oliveira";
	this->m_cabecalho += Texto+"\n";
	Texto.clear();
	Texto = "                               CPF: 174.630.841-91";
	this->m_cabecalho += Texto+"\n";
	Texto.clear();
	Texto = "   Tabelião de Protesto de Títulos - 3º Tabelião de Notas";
	this->m_cabecalho += Texto+"\n";			
	Texto.clear();
	Texto = "       Av. Presidente Vargas, 329 Centro - Dourados-MS";
	this->m_cabecalho += Texto+"\n";
	Texto.clear();
	Texto = "   CEP 79804-030 - Fones: (67) 3422-5311 / 2108-2550";	
	this->m_cabecalho += Texto+"\n\n";
	}

/**
 * 
 */
void PrintFormOperation::set_corpo(int tipo, string data, int recibo) 
	{ 
	BANCOPG *banco;
	string SQL, TP, REC, func, deb_cred, AUX2, AUXF, Linha, auxM;
	Glib::ustring AUX;
	vector<vector<string> >::iterator ir;
	vector<string> linha;
	char *aux, *sql;
	int tp_nat,i,j,tam,qtd, cod_s,it;
	float tt, tt_liq, desc, valor[4], imp[2], aux_f, valor_bissqn;
	bool fj10;
	this->data = data;
	imp[0] = 0.0;
	imp[1] = 0.0;
	aux = new char[10];
	itoa(tipo,aux,10);
	TP.clear();
	if (tipo == 3)
		{
		TP = "1";
		}
	else
		{
		TP.append(aux);
		}
	delete aux;
	aux = new char[32];
	itoa(recibo,aux,10);
	REC.clear();
	REC.append(aux);
	delete aux;
	banco = new BANCOPG(CONF_FILE);
	SQL.clear();
	SQL = "select lancamentos.e_s, lancamentos.rec, lancamentos.data, lancamentos.desconto, lancamentos.total_liq, lancamentos.total, lancamentos.tipo, lancamentos.data_p, lancamentos.protocolo, clientes.nome, clientes.endereco, clientes.documento, clientes.tipo_doc, funcionario.u_login, lancamentos.data_qt, lancamentos.obs, clientes.sub_issqn ";
	SQL += "from caixa.lancamentos inner join cadastro.clientes on lancamentos.cod_cli=clientes.cod_cli inner join cadastro.funcionario on lancamentos.cod_fun=funcionario.cod_fun ";
	SQL += "where lancamentos.e_s="+TP+" and lancamentos.rec="+REC+" and lancamentos.data='"+data+"' and lancamentos.status";
	sql = new char[SQL.length()+1];
	strcpy(sql,SQL.c_str());
	this->m_corpo.clear();
	//cout << sql << endl;
	banco->executar(sql);
	delete sql;
	if (banco->query_result == 3)
		{
		this->m_corpo = banco->mensagem;
		}
	else
		{
		banco->resultado();
		if (banco->registros > 0)
			{
			ir = banco->resultados.begin();
			linha = *ir;
			if (linha.at(16).compare("t") == 0)
				{
				this->s_issqn = true;
				}
			else
				{
				this->s_issqn = false;
				}
			this->m_corpo += "<span size='9216'><b>RECIBO</b>   (";
			deb_cred.clear();
			deb_cred = linha.at(6);
			this->m_corpo+=deb_cred;
			this->m_corpo += ")   ";
			aux = new char[data.length()+1];
			strcpy(aux,data.c_str());
			this->m_corpo.append(data_formatada(aux,2));
			delete aux;
			if (deb_cred.compare ("D") == 0)
				{
				tam = linha.at(14).length();
				if (tam > 0 )
					{
					aux = new char[tam+1];
					strcpy(aux,linha.at(14).c_str());
					this->m_corpo += "   ";
					this->m_corpo.append(data_formatada(aux,2));
					delete aux;
					}
				}
			this->m_corpo += "</span>\n";
			if (linha.at(7).compare("") != 0)
				{
				this->m_corpo += "<span size='8192'>Protocolo: ";
				this->m_corpo += linha.at(8);
				this->m_corpo += " Data: ";
				aux = new char[linha.at(7).length()+1];
				strcpy(aux,linha.at(7).c_str());
				this->m_corpo.append(data_formatada(aux,2));
				this->m_corpo += "</span>\n";
				}
			this->m_corpo += "<span size='7700'>  \n";
			auxM.clear();
			auxM = linha.at(9);
			cout << auxM << endl;
			it = auxM.find("&");
			if (it!=string::npos)
				{
				auxM.replace(it,1,"&amp;");
				}
			cout << auxM << endl;
			this->m_corpo += auxM;
			this->m_corpo += "\n  ";
			this->m_corpo += Glib::ustring(linha.at(10));
			this->m_corpo += "\n  ";
			tp_nat = atoi(linha.at(12).c_str());
			if (tp_nat != 0)
				{
				aux = new char[linha.at(11).length()+1];
				strcpy(aux,linha.at(11).c_str());
				this->m_corpo.append(masc_doc(aux,tp_nat,2));
				delete aux;
				}
			this->m_corpo += "\n";
			this->m_corpo += Glib::ustring(linha.at(15));
			this->m_corpo += "</span>\n";
			if (linha.at(15).length() != 0)
				{
				this->m_corpo += "\n";
				}
			func.clear();
			func = linha.at(13);
			AUXF.clear();
			AUXF = linha.at(4);
			//cout << AUXF << endl;
			it = AUXF.find(".");
			if (it!=string::npos)
				{
				AUXF.replace(it,1,",");
				}
			aux = new char[32];
			strcpy(aux,AUXF.c_str());
			tt = atof(aux);
			//cout << "192 " << tt << endl;
			delete aux;
			AUXF.clear();
			AUXF = linha.at(5);
			//cout << AUXF << endl;
			it = AUXF.find(".");
			if (it!=string::npos)
				{
				AUXF.replace(it,1,",");
				}
			aux = new char[32];
			strcpy(aux,AUXF.c_str());
			tt_liq = atof(aux);
			//cout << "205 " << tt_liq << endl;
			delete aux;
			AUXF.clear();
			AUXF = linha.at(3);
			//cout << AUXF << endl;
			it = AUXF.find(".");
			if (it!=string::npos)
				{
				AUXF.replace(it,1,",");
				}
			aux = new char[32];
			strcpy(aux,AUXF.c_str());
			desc = atof(aux);
			//cout << "218 " << desc << endl;
			delete aux;
			SQL.clear();
			SQL = "select servicos.descricao, entrada.qtd, entrada.valor, entrada.total, entrada.total_liq, entrada.desconto, servicos.f10, entrada.funjecc10, entrada.issqn, servicos.cod_serv ";
			SQL += "from caixa.entrada inner join cadastro.servicos on entrada.cod_serv=servicos.cod_serv ";
			SQL += "where entrada.e_s="+TP+" and entrada.rec="+REC+" and entrada.data='"+data+"' order by servicos.codigo";
			sql = new char[SQL.length()+1];
			//cout << SQL << endl;
			strcpy(sql,SQL.c_str());
			banco->executar(sql);
			delete sql;
			this->m_corpo += "QTD\tDescrição\t\t\t\tValor\n";
			if (banco->query_result == 3)
				{
				this->m_corpo += banco->mensagem;
				}
			else
				{
				if (banco->registros > 0)
					{
					valor[3] = 0.0;
					fj10 = false;
					banco->resultado();
					for (i=0,ir=banco->resultados.begin(); i < banco->registros, ir < banco->resultados.end(); i++,ir++)
						{
						linha = *ir;
						//cout << "imprimir.C: " << __LINE__ << banco->resultado(i,9) << " == " << linha.at(9) << endl;
						cod_s = atoi(linha.at(9).c_str());
						aux = new char[32];
						strcpy(aux,linha.at(1).c_str());
						AUX.clear();
						AUX = casa_milhar(aux,1);
						delete aux;
						this->m_corpo+=AUX+"\t";
						this->m_corpo += linha.at(0);
						this->m_corpo += "\t";
						tam = linha.at(0).length();
						//cout << tam << endl;
						if (tam < 25)
							{
							this->m_corpo += "\t";
							if (tam <= 4)
								{
								this->m_corpo += "             \t";
								}
							else if (tam <= 5)
								{
								this->m_corpo += "\t              ";
								}
							else if (tam <= 6)
								{
								this->m_corpo += "\t            ";
								}
							else if (tam <= 7)
								{
								this->m_corpo += "\t           ";
								}
							else if (tam <= 8)
								{
								this->m_corpo += "\t\t";
								}
							else if (tam <= 9)
								{
								if (cod_s == 8)
									{
									this->m_corpo += "\t";
									}	
								else
									{
									this->m_corpo += "\t\t ";
									}
								}
							else if (tam <= 10)
								{
								this->m_corpo += "\t\t";
								}
							else if (tam <= 11)
								{
								if (cod_s == 15)
									{
									this->m_corpo += "\t";
									}
								else
									{
									this->m_corpo += "\t           ";
									}
								}
							else if (tam <= 13)
								{
								this->m_corpo += "\t";
								}
							else if (tam <= 15)
								{
								this->m_corpo += "\t";
								}
							}
						AUXF.clear();
						AUXF = linha.at(2);
						//cout << AUXF << endl;
						it = AUXF.find(".");
						if (it!=string::npos)
							{
							AUXF.replace(it,1,",");
							}
						aux = new char[32];
						strcpy(aux,AUXF.c_str());
						valor[0] = atof(aux);
						//cout << "imprimir.C: " << __LINE__ << valor[0] << endl;
						delete aux;
						AUXF.clear();
						AUXF = linha.at(3);
						//cout << AUXF << endl;
						it = AUXF.find(".");
						if (it!=string::npos)
							{
							AUXF.replace(it,1,",");
							}
						aux = new char[32];
						strcpy(aux,AUXF.c_str());
						valor[1] = atof(aux);
						//cout << "imprimir.C: " << __LINE__ << valor[1] << endl;
						delete aux;
						AUXF.clear();
						AUXF = linha.at(5);
						//cout << AUXF << endl;
						it = AUXF.find(".");
						if (it!=string::npos)
							{
							AUXF.replace(it,1,",");
							}
						aux = new char[32];
						strcpy(aux,AUXF.c_str());
						valor[2] = atof(aux);
						//cout << "imprimir.C: " << __LINE__ << valor[2] << endl;
						delete aux;
						valor[3] += (valor[1] + valor[2]) - valor[0];
						//cout << valor[3] << "=(" << valor[1] << "+" << valor[2] << ")-" << valor[0] << endl;
						aux = new char[32];
						sprintf(aux,"%0.3f",valor[0]);
						aux[strlen(aux)-1] = '\0';
						cout << __FILE__ << ": " << __LINE__ << endl;
						AUX.clear();
						AUX = casa_milhar(aux,0);
						delete aux;
						tam = AUX.length();
						//cout << tam << endl;
						if (tam == 4)
							{
							this->m_corpo += "         ";
							}
						else if (tam <= 5)
							{
							this->m_corpo += "       ";
							}
						else if (tam <= 6)
							{
							if (cod_s == 8)
								{
								this->m_corpo += "     ";
								}
							else
								{
								this->m_corpo += "   ";
								}
							}
						else if (tam <= 7)
							{
							this->m_corpo += "    ";
							}
						else if (tam <= 8)
							{
							if (cod_s != 14)
								{
								this->m_corpo += "  ";
								}
							}
						this->m_corpo += AUX;
						this->m_corpo +="\n";
						if (linha.at(6).compare("t") == 0)
						    {
							fj10 = true;
							AUXF.clear();
							AUXF = linha.at(7);
							//cout << AUXF << endl;
							it = AUXF.find(".");
							if (it!=string::npos)
								{
								AUXF.replace(it,1,",");
								}
							aux = new char[32];
							strcpy(aux,AUXF.c_str());
							aux_f = atof(aux);
							//cout << __FILE__ << ": " << __LINE__ << " " << aux_f << endl;
							delete aux;
							imp[0] += aux_f;
							AUXF.clear();
							AUXF = linha.at(8);
							//cout << AUXF << endl;
							it = AUXF.find(".");
							if (it!=string::npos)
								{
								AUXF.replace(it,1,",");
								}
							aux = new char[32];
							strcpy(aux,AUXF.c_str());
							aux_f = atof(aux);
							//cout << __FILE__ << ": " << __LINE__ << " " << aux_f << endl;
							delete aux;
							imp[1] += aux_f;
							}
						}
					}
				else
					{
					this->m_corpo += "Registros não encontrados!";
					}
				if (fj10)
					{
					this->m_corpo += "1\tFUNJECC\t\t\t\t";
					aux = new char[32];
					sprintf(aux,"%0.3f",imp[0]);
					aux[strlen(aux)-1] = '\0';
					cout << __FILE__ << ": " << __LINE__ << " " << endl;
					AUX.clear();
					AUX = casa_milhar(aux,0);
					delete aux;
					tam = AUX.length();
					if (tam == 4)
						{
						this->m_corpo += "         ";
						}
					else if (tam <= 5)
						{
						this->m_corpo += "       ";
						}
					else if (tam <= 6)
						{
						this->m_corpo += "     ";
						}
					else if (tam <= 7)
						{
						this->m_corpo += "  ";
						}
					this->m_corpo += AUX;
					this->m_corpo +="\n";
					if (!this->s_issqn)
						{
						this->m_corpo += "1\tISSQN\t\t\t\t";
						aux = new char[32];
						sprintf(aux,"%0.3f",imp[1]);
						aux[strlen(aux)-1] = '\0';
						cout << __FILE__ << ": " << __LINE__ << " " << endl;
						AUX.clear();
						AUX = casa_milhar(aux,0);
						delete aux;
						tam = AUX.length();
						if (tam == 4)
							{
							this->m_corpo += "         ";
							}
						else if (tam <= 5)
							{
							this->m_corpo += "       ";
							}
						else if (tam <= 6)
							{
							this->m_corpo += "     ";
							}
						else if (tam <= 7)
							{
							this->m_corpo += "  ";
							}
						this->m_corpo += AUX;
						this->m_corpo +="\n";
						}
					}
				for (j=0; j < 48; j++)
					{
					this->m_corpo+="_";
					}
				this->m_corpo+="<span size='9216'>\n\tTOTAL\t\t\t";
				aux = new char[32];
				sprintf(aux,"%0.3f",tt_liq);
				aux[strlen(aux)-1] = '\0';
				cout << __FILE__ << ": " << __LINE__ << " " << endl;
				AUX.clear();
				AUX = casa_milhar(aux,0);
				delete aux;
				tam = AUX.length();
				if (tam == 4)
					{
					this->m_corpo += "  ";
					}
				if (tam <= 5)
					{
					this->m_corpo += "        ";
					}
				if (tam <= 6)
					{
					this->m_corpo += " ";
					}
				if (tam <= 7)
					{
					this->m_corpo += "  ";
					}
				this->m_corpo += "  "+AUX;
				/*aux = new char[32];
				sprintf (aux,"%0.3f",desc);
				aux[strlen(aux)-1] = '\0';
				cout << __FILE__ << ": " << __LINE__ << " " << endl;
				AUX.clear();
				AUX = casa_milhar(aux,0);
				delete aux;
				tam = AUX.length();
				if (tam == 4)
					{
					this->m_corpo += "  ";
					}
				if (tam <= 5)
					{
					this->m_corpo += "    ";
					}
				if (tam == 6)
					{
					this->m_corpo += "\t";
					}
				if (tam <= 7)
					{
					this->m_corpo += "  ";
					}
				if (tam <= 8)
					{
					this->m_corpo += "  ";
					}
				this->m_corpo += "\t"+AUX;
				aux = new char[32];
				sprintf (aux,"%0.3f",tt_liq);
				aux[strlen(aux)-1] = '\0';
				cout << __FILE__ << ": " << __LINE__ << " " << endl;
				AUX.clear();
				AUX = casa_milhar(aux,0);
				delete aux;
				tam = AUX.length();
				if (tam == 4)
					{
					this->m_corpo += "  ";
					}
				if (tam <= 5)
					{
					this->m_corpo += "    ";
					}
				if (tam <= 6)
					{
					this->m_corpo += "  ";
					}
				if (tam <= 7)
					{
					this->m_corpo += "  ";
					}
				else if (tam <= 8)
					{
					this->m_corpo += "\t";
					}
				this->m_corpo += "\t"+AUX;*/
				this->m_corpo += "</span>\n";
				this->m_corpo += "\t\t\t\t\t<span size='7168'>"+func+"</span>\n";
				if (this->s_issqn)
					{
					valor_bissqn = (imp[1]*100)/5;
					aux = new char[32];
					sprintf(aux,"%0.3f",valor_bissqn);
					aux[strlen(aux)-1] = '\0';
					cout << __FILE__ << ": " << __LINE__ << " " << endl;
					AUX.clear();
					AUX = casa_milhar(aux,0);
					delete aux;
					this->m_corpo += "Base de Cálculo ISSQN: R$ "+AUX +"\n"; 
					}
				}
			}
		else
			{
			this->m_corpo = "Recibo não encontrado!";
			}
		}
	delete banco;
	}

/**
 * 
 */
void PrintFormOperation::set_rodape() 
	{ 
	Glib::ustring Texto, AUX;
	char *aux;
	int deslocar, i;

	this->m_rodape.clear();
	for (i=0; i < 48; i++)
		{
		this->m_rodape += "_";
		}
	Texto.clear();
	Texto = "       TESTAMENTOS - ESCRITURAS - PROCURAÇÕES\n                FIRMAS - AUTENTICAÇÕES - PROTESTO";
	aux = new char[this->data.length()+1];
	strcpy(aux,this->data.c_str());
	Texto += "\n";
	Texto.append(data_formatada(aux,2));
	delete aux;
	this->m_rodape += "\n<span size='7680'>"+Texto+"</span>\n\n\n";
	}

/**
 * 
 */
void PrintFormOperation::on_begin_print(const Glib::RefPtr<Gtk::PrintContext>& print_context)
	{
	//Create and set up a Pango layout for PrintData based on the passed
  	//PrintContext: We then use this to calculate the number of pages needed, and
  	//the lines that are on each page.
	Formulario = print_context->create_pango_layout();
	
	Pango::FontDescription font_desc("Arial 8");
	Formulario->set_font_description(font_desc);

  	const double width = print_context->get_width();
	this->largura = width;
  	const double height = print_context->get_height();
	this->altura = height;

  	Formulario->set_width(static_cast<int>(width * Pango::SCALE));
	Formulario->set_alignment(Pango::ALIGN_LEFT);
	this->set_cabecalho();
	this->set_rodape();
	
  	Formulario->set_markup(this->m_cabecalho+this->m_corpo+this->m_rodape);
	
	//Set the number of pages to print by determining the line numbers
	//where page breaks occur:
	const int line_count = Formulario->get_line_count();

	Glib::RefPtr<Pango::LayoutLine> layout_line;
	double page_height = 0;

  	for (int line = 0; line < line_count; ++line)
	  	{
		Pango::Rectangle ink_rect, logical_rect;

		layout_line = Formulario->get_line(line);
		layout_line->get_extents(ink_rect, logical_rect);

		const double line_height = logical_rect.get_height() / 1024.0;

		if (page_height + line_height > height)
			{
			QuebraPagina.push_back(line);
			page_height = 0;
			}

		page_height += line_height;
	  	}

  	set_n_pages(QuebraPagina.size() + 1);

	}

/**
 * 
 */
void PrintFormOperation::on_draw_page(const Glib::RefPtr<Gtk::PrintContext>& print_context, int page_nr)
	{
	//Decide which lines we need to print in order to print the specified page:
	int start_page_line = 0;
	int end_page_line = 0;

  	if(page_nr == 0)
		{
		start_page_line = 0;
		}
  	else
  		{
   		start_page_line = QuebraPagina[page_nr - 1];
  		}

  	if(page_nr < static_cast<int>(QuebraPagina.size()))
  		{
    	end_page_line = QuebraPagina[page_nr];
  		}
  	else
  		{
    	end_page_line = Formulario->get_line_count();
  		}

  	//Get a Cairo Context, which is used as a drawing board:
  	Cairo::RefPtr<Cairo::Context> cairo_ctx = print_context->get_cairo_context();

  	//We'll use black letters:
  	cairo_ctx->set_source_rgb(0, 0, 0);

  	//Render Pango LayoutLines over the Cairo context:
  	Pango::LayoutIter iter;
  	Formulario->get_iter(iter);

  	double start_pos = 0;
  	int line_index = 0;

  	do
  		{
    	if (line_index >= start_page_line)
    		{
      		Glib::RefPtr<Pango::LayoutLine> layout_line = iter.get_line();
      		Pango::Rectangle logical_rect = iter.get_line_logical_extents();
      		int baseline = iter.get_baseline();

		  	if (line_index == start_page_line)
		  		{
		    	start_pos = logical_rect.get_y() / 1024.0;
		  		}

      		cairo_ctx->move_to(logical_rect.get_x() / 1024.0, baseline / 1024.0 - start_pos);

      		layout_line->show_in_cairo_context(cairo_ctx);
    		}

    	line_index++;
  		}while (line_index < end_page_line && iter.next_line());
	}

/**
 * 
 */
void IMPRIMIR::on_printoperation_status_changed(const Glib::RefPtr<PrintFormOperation>& operation)
	{
  	Glib::ustring status_msg;

  	if (operation->is_finished())
	  	{
		status_msg = "Print job completed.";
	  	}
 	else
	  	{
		//You could also use get_status().
		status_msg = operation->get_status_string();
	  	}	
	}

/**
 * 
 */
void IMPRIMIR::on_printoperation_done(Gtk::PrintOperationResult result,const Glib::RefPtr<PrintFormOperation>& operation)
	{
  	//Printing is "done" when the print data is spooled.

  	if (result == Gtk::PRINT_OPERATION_RESULT_ERROR)
		{
		Gtk::MessageDialog err_dialog(*this, "Error printing form", false,Gtk::MESSAGE_ERROR, Gtk::BUTTONS_OK, true);
    	err_dialog.run();
	  	}
  	else if (result == Gtk::PRINT_OPERATION_RESULT_APPLY)
	  	{
		//Update PrintSettings with the ones used in this PrintOperation:
		ConfImpress = operation->get_print_settings();
	  	}

  	if (! operation->is_finished())
  		{
		//We will connect to the status-changed signal to track status
		//and update a status bar. In addition, you can, for example,
		//keep a list of active print operations, or provide a progress dialog.
		operation->signal_status_changed().connect(sigc::bind(sigc::mem_fun(*this,&IMPRIMIR::on_printoperation_status_changed),operation));
	  	}
	}

/**
 * 
 */
IMPRIMIR::IMPRIMIR(BANCOPG *conecao, int tipo, string data, int recibo, bool impresso)
  	{
	this->conexao = conecao;  
	this->tipo = tipo;
	this->data = data;
	this->recibo = recibo;
	const Gtk::PaperSize papel("Recibo-Paper","Recibo-Paper",85,170,Gtk::UNIT_MM);
  	SetupPagina = Gtk::PageSetup::create();
	SetupPagina->set_paper_size (papel);
	SetupPagina->set_right_margin(0,Gtk::UNIT_MM);
	SetupPagina->set_left_margin(7,Gtk::UNIT_MM);
  	ConfImpress = Gtk::PrintSettings::create();
	set_type_hint(Gdk::WINDOW_TYPE_HINT_DIALOG);
  	set_position(Gtk::WIN_POS_CENTER);
	set_title(Glib::ustring("Visualização do Recibo"));
	set_size_request(300,600);
  	Box_Principal.set_homogeneous(false); 
	Box_Principal.set_spacing(0);

	Box_Menu.set_homogeneous(false);
	Box_Menu.set_spacing(0);

	b_setup.signal_clicked().connect(sigc::mem_fun(*this,&IMPRIMIR::Imprimir_Config));
	b_setup.set_stock_id(Gtk::Stock::PROPERTIES);
	b_setup.set_label("Configurar");
	b_preview.set_stock_id(Gtk::Stock::PRINT_PREVIEW);
	b_preview.set_label("Visualizar");
	b_preview.signal_clicked().connect(sigc::mem_fun(*this,&IMPRIMIR::Imprimir_Preview));
	b_imprimir.set_stock_id(Gtk::Stock::PRINT);
  	b_imprimir.set_label("Imprimir");
	b_imprimir.signal_clicked().connect(sigc::mem_fun(*this,&IMPRIMIR::Imprimir));
	b_fechar.set_stock_id(Gtk::Stock::CLOSE);
	b_fechar.set_label("Fechar");
	b_fechar.signal_clicked().connect(sigc::mem_fun(*this,&IMPRIMIR::fechar));

	tb_imprimir.append(b_imprimir);
	tb_imprimir.append(b_setup);
	tb_imprimir.append(b_preview);
	tb_imprimir.append(b_separador);
	tb_imprimir.append(b_fechar);
	
	Box_Menu.pack_start(tb_imprimir,false,true,0);
	Box_Conteudo.set_homogeneous(false);
	Box_Conteudo.set_spacing(0);

	PVisualiza = TVisualiza.get_buffer();
	tags_create();
	gerar_texto();
	TVisualiza.set_justification(Gtk::JUSTIFY_FILL);
	TVisualiza.set_buffer(PVisualiza);
	TVisualiza.set_editable(false);
	SVisualiza.add(TVisualiza);
	SVisualiza.set_policy(Gtk::POLICY_NEVER, Gtk::POLICY_AUTOMATIC);

	Box_Conteudo.pack_start(SVisualiza,true,true,0);
			
	Box_Principal.pack_start(Box_Menu,false,true,0);
	Box_Principal.pack_start(Box_Conteudo,true,true,0);
			
	add(Box_Principal);
	if (impresso)
		{
		b_imprimir.set_sensitive (false);
		b_setup.set_sensitive (false);
		b_preview.set_sensitive (false);
		}
	show_all();
	}

/**
 * 
 */
IMPRIMIR::~IMPRIMIR()
	{
	fechar();
	}

/**
 * 
 */
void IMPRIMIR::print_or_preview(Gtk::PrintOperationAction print_action)
	{
	//Create a new PrintOperation with our PageSetup and PrintSettings:
  	//(We use our derived PrintOperation class)
  	Glib::RefPtr<PrintFormOperation> print = PrintFormOperation::create();

  	print->set_corpo(this->tipo,this->data,this->recibo);

  	print->set_track_print_status();
  	print->set_default_page_setup(SetupPagina);
  	print->set_print_settings(ConfImpress);

  	print->signal_done().connect(sigc::bind(sigc::mem_fun(*this,&IMPRIMIR::on_printoperation_done), print));
  	try
  		{
    	print->run(print_action /* print or preview */, *this);
  		}
  	catch (const Gtk::PrintError& ex)
  		{
    	//See documentation for exact Gtk::PrintError error codes.
    	std::cerr << "An error occurred while trying to run a print operation:" << ex.what() << std::endl;
  		}
	}

/**
 * 
 */
void IMPRIMIR::on_menu_file_new()
	{
  
	}

/**
 * 
 */
void IMPRIMIR::Imprimir_Config()
	{
  	//Show the page setup dialog, asking it to start with the existing settings:
  	Glib::RefPtr<Gtk::PageSetup> new_page_setup = Gtk::run_page_setup_dialog(*this, this->SetupPagina, this->ConfImpress);

  	//Save the chosen page setup dialog for use when printing, previewing, or
  	//showing the page setup dialog again:
  	this->SetupPagina = new_page_setup;
	}

/**
 * 
 */
void IMPRIMIR::Imprimir_Preview()
	{
  	print_or_preview(Gtk::PRINT_OPERATION_ACTION_PREVIEW);
	}

/**
 * 
 */
void IMPRIMIR::Imprimir()
	{
  	print_or_preview(Gtk::PRINT_OPERATION_ACTION_PRINT_DIALOG);
	b_imprimir.set_sensitive (false);
	b_setup.set_sensitive (false);
	b_preview.set_sensitive (false);
	}

/**
 * 
 */
void IMPRIMIR::fechar()
	{
  	hide();
	}

/**
 * 
 */
void IMPRIMIR::corpo(const Glib::ustring& texto)
	{
	//this->corpo_text = texto;
	PVisualiza = TVisualiza.get_buffer();
	this->corpo_text = PVisualiza->get_text();
	}

/**
 * 
 */
void IMPRIMIR::tags_create()
	{
	tags = PVisualiza->create_tag("geral");
	tags->property_font() = "Arial 10";
	tags->property_wrap_mode () = Gtk::WRAP_WORD;
	tags->property_left_margin() = 20;
	tags->property_right_margin() = 20;
	tags = PVisualiza->create_tag ("font7");
	tags->property_font() = "Arial 7";
	tags->property_wrap_mode() = Gtk::WRAP_WORD;
	tags = PVisualiza->create_tag ("font8");
	tags->property_font() = "Arial 8";
	tags->property_wrap_mode() = Gtk::WRAP_WORD;
	tags = PVisualiza->create_tag ("font9");
	tags->property_font() = "Arial 9";
	tags->property_wrap_mode() = Gtk::WRAP_WORD;
	tags = PVisualiza->create_tag ("font14");
	tags->property_font() = "Arial 14";
	tags->property_wrap_mode() = Gtk::WRAP_WORD;
	tags = PVisualiza->create_tag("cabecalho_l");
	tags->property_font() = "Arial 14";
	tags->property_wrap_mode() = Gtk::WRAP_WORD;
	tags->property_justification() = Gtk::JUSTIFY_LEFT;
	tags = PVisualiza->create_tag("cabecalho_r");
	tags->property_font() = "Arial 14";
	tags->property_wrap_mode() = Gtk::WRAP_WORD;
	tags->property_justification() = Gtk::JUSTIFY_RIGHT;
	tags = PVisualiza->create_tag("centralizar");
	tags->property_justification() = Gtk::JUSTIFY_CENTER;
	tags = PVisualiza->create_tag("sublinhado");
	tags->property_underline() = Pango::UNDERLINE_SINGLE;
	tags = PVisualiza->create_tag("negrito");
	tags->property_weight() = Pango::WEIGHT_BOLD;
	tags = PVisualiza->create_tag("esquerda");
	tags->property_justification() = Gtk::JUSTIFY_LEFT;
	tags = PVisualiza->create_tag("direita");
	tags->property_justification() = Gtk::JUSTIFY_RIGHT;
	}

/**
 * 
 */
void IMPRIMIR::gerar_texto()
	{
	int tam,i,tp_nat,j,qtd,it;
	char *sql, *buf, *aux;
	string buffer, SQL, TP, REC, func, AUX, DC("Crédito");
	vector<vector<string> >::iterator ir;
	vector<string> linha;
	Glib::ustring BUFFER;
	vector<string> nomes_tags;
	float tt, tt_liq, desc, valor[4], imp[2], aux_f, valor_bissqn;
	bool fj10;
	imp[0] = 0.0;
	imp[1] = 0.0;
		
	aux = new char[32];
	sprintf(aux,"%d",this->tipo);
	TP.clear();
	TP.append(aux);
	delete aux;
	aux = new char[32];
	sprintf(aux,"%d",this->recibo);
	REC.clear();
	REC.append(aux);
	delete aux;
	// Cabeçalho - Begin
	iter = PVisualiza->get_iter_at_offset(0);
	nomes_tags.clear();
	nomes_tags.push_back("centralizar");
	nomes_tags.push_back("negrito");
	PVisualiza->insert_with_tags_by_name(iter,Glib::ustring("TABELIONATO OLIVEIRA"),nomes_tags);
	iter = PVisualiza->end();
	nomes_tags.clear();
	nomes_tags.push_back("centralizar");
	nomes_tags.push_back("font8");
	buffer.clear();
	buffer = "\nBel. Marcelino Cesar Medeiros\n";
	buffer += "\nCPF: 174.630.841-91\n";
	buffer += "Tabelião de Protesto de Títulos - 3º Tabelião de Notas\n";
	buffer += "Av. Presidente Vargas, 329 Centro - Dourados-MS\n";
	buffer += "Fones: (67) 3422-5311 / 2108-2550\n";
	buffer += "tabelionatooliveira@tabelionatooliveira.com.br\n";
	PVisualiza->insert_with_tags_by_name(iter,Glib::ustring(buffer),nomes_tags);
	iter = PVisualiza->end();
	// Cabeçalho - End
	SQL.clear();
	SQL = "select lancamentos.e_s, lancamentos.rec, lancamentos.data, lancamentos.desconto, lancamentos.total_liq, lancamentos.total, lancamentos.tipo, lancamentos.data_p, lancamentos.protocolo, clientes.nome, clientes.endereco, clientes.documento, clientes.tipo_doc, funcionario.u_login, lancamentos.data_qt, lancamentos.obs, clientes.sub_issqn ";
	SQL += "from caixa.lancamentos inner join cadastro.clientes on lancamentos.cod_cli=clientes.cod_cli inner join cadastro.funcionario on lancamentos.cod_fun=funcionario.cod_fun ";
	SQL += "where lancamentos.e_s="+TP+" and lancamentos.rec="+REC+" and lancamentos.data='"+this->data+"' and lancamentos.status";
	sql = new char[SQL.length()+1];
	strcpy(sql,SQL.c_str());
	//cout << sql << endl;
	this->conexao->executar(sql);
	delete sql;
	if (this->conexao->query_result == 3)
		{
		nomes_tags.clear();
		nomes_tags.push_back("negrito");
		nomes_tags.push_back("font8");
		buffer.clear();
		buffer = this->conexao->mensagem;
		PVisualiza->insert_with_tags_by_name(iter,Glib::ustring(buffer),nomes_tags);
		iter = PVisualiza->end();
		}
	else
		{
		this->conexao->resultado();
		ir = this->conexao->resultados.begin();
		linha = *ir;
		if (linha.at(16).compare("t") == 0)
			{
			this->s_issqn = true;
			}
		else
			{
			this->s_issqn = false;
			}
		func.clear();
		func = linha.at(13);
		AUX.clear();
		AUX = linha.at(4);
		//cout << AUX << endl;
		it = AUX.find(".");
		if (it!=string::npos)
			{
			AUX.replace(it,1,",");
			}
		aux = new char[32];
		strcpy(aux,AUX.c_str());
		tt = atof(aux);
		//cout << __FILE__ << ": " << __LINE__ << " " << tt << endl;
		delete aux;
		AUX.clear();
		AUX = linha.at(5);
		//cout << AUX << endl;
		it = AUX.find(".");
		if (it!=string::npos)
			{
			AUX.replace(it,1,",");
			}
		aux = new char[32];
		strcpy(aux,AUX.c_str());
		tt_liq = atof(aux);
		//cout << __FILE__ << ": " << __LINE__ << " " << tt_liq << endl;
		delete aux;
		AUX.clear();
		AUX = linha.at(3);
		//cout << AUX << endl;
		it = AUX.find(".");
		if (it!=string::npos)
			{
			AUX.replace(it,1,",");
			}
		aux = new char[32];
		strcpy(aux,AUX.c_str());
		desc = atof(aux);
		//cout << __FILE__ << ": " << __LINE__ << " " << desc << endl;
		delete aux;
		nomes_tags.clear();
		nomes_tags.push_back("negrito");
		nomes_tags.push_back("font8");
		buffer.clear();
		buffer = "RECIBO";
		PVisualiza->insert_with_tags_by_name(iter,Glib::ustring(buffer),nomes_tags);
		iter = PVisualiza->end();
		nomes_tags.clear();
		nomes_tags.push_back("font8");
		buffer.clear();
		buffer = " (";
		buffer += linha.at(6);
		buffer += ") ";
		aux = new char[32];
		strcpy(aux,linha.at(2).c_str());
		buffer += data_formatada(aux,2) ;
		delete aux;
		if (linha.at(6).compare("D") == 0)
			{
			DC.clear();
			DC = "Débito";
			aux = new char[32];
			strcpy(aux,linha.at(14).c_str());
			buffer +=  "  ";
			buffer += data_formatada(aux,2);
			delete aux;
			}
		buffer += "\n";
		if (linha.at(7).compare("") != 0)
			{
			buffer += "Protocolo: ";
			buffer += linha.at(8);
			buffer += " Data: ";
			aux = new char[linha.at(7).length()+1];
			strcpy(aux,linha.at(7).c_str());
			buffer.append(data_formatada(aux,2));
			buffer += "\n";
			}
		PVisualiza->insert_with_tags_by_name(iter,Glib::ustring(buffer),nomes_tags);
		iter = PVisualiza->end();
		nomes_tags.clear();
		nomes_tags.push_back("font7");
		buffer.clear();
		buffer += linha.at(9);
		buffer += "\n  ";
		buffer += linha.at(10);
		buffer += "\n  ";
		tp_nat = atoi(linha.at(12).c_str());
		if (tp_nat != 0)
			{
			aux = new char[linha.at(11).length()+1];
			strcpy(aux,linha.at(11).c_str());
			buffer.append(masc_doc(aux,tp_nat,2));
			delete aux;
			}
		buffer += "\n";
		buffer += linha.at(15);
		buffer += "\n";
		if (linha.at(15).length() != 0)
			{
			buffer += "\n";
			}
		PVisualiza->insert_with_tags_by_name(iter,Glib::ustring(buffer),nomes_tags);
		iter = PVisualiza->end();
		SQL.clear();
		SQL = "select servicos.descricao, entrada.qtd, entrada.valor, entrada.total, entrada.total_liq, entrada.desconto, servicos.f10, entrada.funjecc10, entrada.issqn ";
		SQL += "from caixa.entrada inner join cadastro.servicos on entrada.cod_serv=servicos.cod_serv ";
		SQL += "where entrada.e_s="+TP+" and entrada.rec="+REC+" and entrada.data='"+data+"' order by servicos.codigo";
		sql = new char[SQL.length()+1];
		//cout << SQL << endl;
		strcpy(sql,SQL.c_str());
		this->conexao->executar(sql);
		delete sql;
		if (this->conexao->query_result == 3)
			{
			nomes_tags.clear();
			nomes_tags.push_back("negrito");
			nomes_tags.push_back("font8");
			buffer.clear();
			buffer = this->conexao->mensagem;
			PVisualiza->insert_with_tags_by_name(iter,Glib::ustring(buffer),nomes_tags);
			iter = PVisualiza->end();
			}
		else
			{
			if (this->conexao->registros > 0)
				{
				nomes_tags.clear();
				nomes_tags.push_back("negrito");
				nomes_tags.push_back("font8");
				buffer.clear();
				buffer = "QTD\tDescrição\t\t\t\tValor\n";
				PVisualiza->insert_with_tags_by_name(iter,Glib::ustring(buffer),nomes_tags);
				iter = PVisualiza->end();
				valor[3] = 0.0;
				fj10 = false;
				this->conexao->resultado();
				for (i=0,ir=this->conexao->resultados.begin(); i < this->conexao->registros,ir < this->conexao->resultados.end(); i++,ir++)
					{
					linha = *ir;
					nomes_tags.clear();
					nomes_tags.push_back("font8");
					aux = new char[32];
					strcpy(aux,linha.at(1).c_str());
					AUX.clear();
					AUX = casa_milhar(aux,1);
					delete aux;
					buffer.clear();
					buffer = AUX;
					buffer += "\t";
					buffer += linha.at(0);
					buffer += " ";
					PVisualiza->insert_with_tags_by_name(iter,Glib::ustring(buffer),nomes_tags);
					iter = PVisualiza->end();
					AUX.clear();
					AUX = linha.at(2);
					//cout << AUX << endl;
					it = AUX.find(".");
					if (it!=string::npos)
						{
						AUX.replace(it,1,",");
						}
					aux = new char[32];
					strcpy(aux,AUX.c_str());
					valor[0] = atof(aux);
					//cout << __FILE__ << ": " << __LINE__ << " " << valor[0] << endl;
					delete aux;
					AUX.clear();
					AUX = linha.at(3);
					//cout << AUX << endl;
					it = AUX.find(".");
					if (it!=string::npos)
						{
						AUX.replace(it,1,",");
						}
					aux = new char[32];
					strcpy(aux,AUX.c_str());
					valor[1] = atof(aux);
					//cout << __FILE__ << ": " << __LINE__ << " " << valor[1] << endl;
					delete aux;
					AUX.clear();
					AUX = linha.at(5);
					//cout << AUX << endl;
					it = AUX.find(".");
					if (it!=string::npos)
						{
						AUX.replace(it,1,",");
						}
					aux = new char[32];
					strcpy(aux,AUX.c_str());
					valor[2] = atof(aux);
					//cout << __FILE__ << ": " << __LINE__ << " " << valor[2] << endl;
					delete aux;
					valor[3] += (valor[1] + valor[2]) - valor[0];
					//cout << valor[3] << "=(" << valor[1] << "+" << valor[2] << ")-" << valor[0] << endl;
					aux = new char[32];
					sprintf(aux,"%0.3f",valor[0]);
					aux[strlen(aux)-1] = '\0';
					cout << __FILE__ << ": " << __LINE__ << endl;
					AUX.clear();
					AUX = casa_milhar(aux,0);
					delete aux;
					nomes_tags.clear();
					nomes_tags.push_back("font8");
					nomes_tags.push_back("direita");
					buffer.clear();
					tam = AUX.length();
					if (tam < 25)
						{
						buffer += "\t";
						if (tam <= 5)
							{
							buffer += "           \t";
							}
						else if (tam <= 7)
							{
							buffer += "\t\t";
							}
						else if (tam <= 8)
							{
							buffer += "  \t";
							}
						else if (tam <= 9)
							{
							buffer += "  ";
							}
						else if (tam <= 10)
							{
							buffer += "\t\t";
							}
						else if (tam <= 13)
							{
							buffer += "\t";
							}
						else if (tam <= 15)
							{
							buffer += "\t";
							}
						}
					buffer += AUX;
					buffer += "\n";
					PVisualiza->insert_with_tags_by_name(iter,Glib::ustring(buffer),nomes_tags);
					iter = PVisualiza->end();
					if (linha.at(6).compare("t") == 0)
						{
						fj10 = true;
						AUX.clear();
						AUX = linha.at(7);
						//cout << AUX << endl;
						it = AUX.find(".");
						if (it!=string::npos)
							{
							AUX.replace(it,1,",");
							}
						aux = new char[32];
						strcpy(aux,AUX.c_str());
						aux_f = atof(aux);
						//cout << __FILE__ << ": " << __LINE__ << " " << aux_f << endl;
						delete aux;
						imp[0] += aux_f;
						AUX.clear();
						AUX = linha.at(8);
						//cout << AUX << endl;
						it = AUX.find(".");
						if (it!=string::npos)
							{
							AUX.replace(it,1,",");
							}
						aux = new char[32];
						strcpy(aux,AUX.c_str());
						aux_f = atof(aux);
						//cout << __FILE__ << ": " << __LINE__ << " " << aux_f << endl;
						delete aux;
						imp[1] += aux_f;
						}
					}
				if (fj10)
					{
					nomes_tags.clear();
					nomes_tags.push_back("font8");
					buffer.clear();
					buffer = "1\tFUNJECC\t\t\t\t";
					aux = new char[32];
					sprintf(aux,"%0.3f",imp[0]);
					aux[strlen(aux)-1] = '\0';
					cout << __FILE__ << ": " << __LINE__ << endl;
					AUX.clear();
					AUX = casa_milhar(aux,0);
					delete aux;
					tam = AUX.length();
					if (tam == 4)
						{
						buffer += "  ";
						}
					if (tam <= 5)
						{
						buffer += "    ";
						}
					if (tam <= 6)
						{
						buffer += " ";
						}
					if (tam <= 7)
						{
						buffer += "  ";
						}
					buffer += AUX;
					buffer +="\n";
					if (!this->s_issqn)
						{
						buffer += "1\tISSQN\t\t\t\t";
						aux = new char[32];
						sprintf(aux,"%0.3f",imp[1]);
						aux[strlen(aux)-1] = '\0';
						cout << __FILE__ << ": " << __LINE__ << endl;
						AUX.clear();
						AUX = casa_milhar(aux,0);
						delete aux;
						tam = AUX.length();
						if (tam == 4)
							{
							buffer += "  ";
							}
						if (tam <= 5)
							{
							buffer += "    ";
							}
						if (tam <= 6)
							{
							buffer += " ";
							}
						if (tam <= 7)
							{
							buffer += "  ";
							}
						buffer += AUX;
						buffer +="\n";
						}
					}
				for (j=0; j < 36; j++)
					{
					buffer+="_";
					}
				PVisualiza->insert_with_tags_by_name(iter,Glib::ustring(buffer),nomes_tags);
				iter = PVisualiza->end();
				nomes_tags.clear();
				nomes_tags.push_back("font9");
				buffer.clear();
				buffer ="\n     Tot. Liq.\t\tDesc.\t\tTotal\n";
				aux = new char[32];
				sprintf(aux,"%0.3f",tt);
				aux[strlen(aux)-1] = '\0';
				cout << __FILE__ << ": " << __LINE__ << endl;
				AUX.clear();
				AUX = casa_milhar(aux,0);
				delete aux;
				tam = AUX.length();
				if (tam == 4)
					{
					buffer += "  ";
					}
				if (tam <= 5)
					{
					buffer += "    ";
					}
				if (tam <= 6)
					{
					buffer += " ";
					}
				if (tam <= 7)
					{
					buffer += "  ";
					}
				buffer += "  "+AUX;
				aux = new char[32];
				sprintf (aux,"%0.3f",desc);
				aux[strlen(aux)-1] = '\0';
				cout << __FILE__ << ": " << __LINE__ << endl;
				AUX.clear();
				AUX = casa_milhar(aux,0);
				delete aux;
				tam = AUX.length();
				if (tam == 4)
					{
					buffer += "  ";
					}
				if (tam <= 5)
					{
					buffer += "    ";
					}
				if (tam == 6)
					{
					buffer += "\t";
					}
				if (tam <= 7)
					{
					buffer += "  ";
					}
				buffer += "\t"+AUX;
				aux = new char[32];
				sprintf (aux,"%0.3f",tt_liq);
				aux[strlen(aux)-1] = '\0';
				cout << __FILE__ << ": " << __LINE__ << endl;
				AUX.clear();
				AUX = casa_milhar(aux,0);
				delete aux;
				tam = AUX.length();
				if (tam == 4)
					{
					buffer += "  ";
					}
				if (tam <= 5)
					{
					buffer += "    ";
					}
				if (tam <= 6)
					{
					buffer += "  ";
					}
				if (tam <= 7)
					{
					buffer += "  ";
					}
				else if (tam <= 8)
					{
					buffer += "\t";
					}
				buffer += "\t"+AUX+"\n";
				PVisualiza->insert_with_tags_by_name(iter,Glib::ustring(buffer),nomes_tags);
				iter = PVisualiza->end();
				nomes_tags.clear();
				nomes_tags.push_back("font7");
				nomes_tags.push_back("direita");
				buffer.clear();
				buffer += func+"\n";
				PVisualiza->insert_with_tags_by_name(iter,Glib::ustring(buffer),nomes_tags);
				iter = PVisualiza->end();
				if (this->s_issqn)
					{
					valor_bissqn = (imp[1]*100)/5;
					aux = new char[32];
					sprintf(aux,"%0.3f",valor_bissqn);
					aux[strlen(aux)-1] = '\0';
					cout << __FILE__ << ": " << __LINE__ << endl;
					AUX.clear();
					AUX = casa_milhar(aux,0);
					delete aux;
					nomes_tags.clear();
					nomes_tags.push_back("font8");
					buffer.clear();
					buffer = "Base de Cálculo ISSQN: R$ "+AUX +"\n"; 
					PVisualiza->insert_with_tags_by_name(iter,Glib::ustring(buffer),nomes_tags);
					iter = PVisualiza->end();
					}
				}
			else
				{
				nomes_tags.clear();
				nomes_tags.push_back("negrito");
				nomes_tags.push_back("font8");
				buffer.clear();
				buffer = "Registros não encontrados!";
				PVisualiza->insert_with_tags_by_name(iter,Glib::ustring(buffer),nomes_tags);
				iter = PVisualiza->end();
				}
			}
		}
	// Rodapé - Begin
	//iter = PVisualiza->end();
	buffer.clear();
	for (i=0; i < 36; i++)
		{
		buffer += "_";
		}
	buffer += "\n";
	PVisualiza->insert_with_tag(iter,Glib::ustring(buffer),"centralizar");
	iter = PVisualiza->end();
	buffer.clear();
	buffer = "TESTAMENTOS - ESCRITURAS - PROCURAÇÕES\nFIRMAS - AUTENTICAÇÕES\n\n";
	nomes_tags.clear();
	nomes_tags.push_back("centralizar");
	nomes_tags.push_back("font8");
	PVisualiza->insert_with_tags_by_name(iter,Glib::ustring(buffer),nomes_tags);
	iter = PVisualiza->end();
	buffer.clear();
	buffer = "Recibo Número: "+REC+"\n"+DC;
	nomes_tags.clear();
	nomes_tags.push_back("negrito");
	nomes_tags.push_back("font14");
	PVisualiza->insert_with_tags_by_name(iter,Glib::ustring(buffer),nomes_tags);
	// Rodapé	- End
	PVisualiza->get_bounds(inicio, final);
	PVisualiza->apply_tag_by_name("geral", inicio, final);
	this->corpo(buffer);
	}
